# -*- coding: utf-8 -*-
# $Id: problemstatwidget.py 27 2009-02-15 19:46:27Z gkuznets $

# Copyright 2008, 2009 Grigoriy Kuznetsov (gkuznets@yandex.ru)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4.QtCore import QString, QTime
from PyQt4.QtGui import QWidget, QGridLayout, QLabel
from gui.colors import *
from checkup import Checkup
checkup = Checkup.instance()

class ProblemStatWidget(QWidget):
    def __init__(self, group, parent=None):
        QWidget.__init__(self, parent)
        self.__group = group
        self.createLayout()
        self.update()
    
    def createLayout(self):
        gl = QGridLayout()
        self.__first_progress = QLabel()
        self.__first_progress.setStyleSheet("background-color: #77FF77;")
        self.__second_progress = QLabel()
        self.__second_progress.setStyleSheet("background-color: #7777FF;")
        self.__speed_lbl = QLabel()
        self.__blist_lbl = QLabel()
        self.__blist_lbl.setWordWrap(True)
        gl.addWidget(self.__first_progress, 0, 0)
        gl.addWidget(self.__second_progress, 0, 1)
        gl.addWidget(self.__speed_lbl, 1, 0, 1, 2)
        gl.addWidget(self.__blist_lbl, 2, 0, 1, 2)
        self.setLayout(gl)
    
    def update(self):
        QWidget.update(self)
        self.__first_progress.setText(QString(str(self.__group.progress(0)) + "%"))
        self.__second_progress.setText(QString(str(self.__group.progress(1)) + "%"))
        speed = 0.0
        if checkup.checkup() >= 0:
            speed = float(self.__group.papers_complete[0] + self.__group.papers_complete[1])/(checkup.startTimes()[0].secsTo(QTime.currentTime())/60.0 + 0.001)
            
        self.__speed_lbl.setText(QString(u"%0.2f р/мин" % speed)) # Скорость проверки работ/мин
        self.__blist_lbl.setText(QString(", ".join([str(b.name()) for b in self.__group.blist])))